'use strict'

var http = require('http');
var cheerio = require('cheerio');
var _ = require('underscore');

var options = {
	host: 'www.lagou.com',
	port: 80,
	path: '/jobs/positionAjax.json?px=default&needAddtionalResult=false&pn=',
	headers:{
		'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36'
	}
};

function getHtml(options,callback) {
    var html;
    http.get(options, function (res) {
        res.on('data', function (data) {
            html += data;
        }); 
        res.on('end', function () {
            callback(html);
        }); 
    })  
}  

function getJobs(count){
	var idx = 0;
	for(idx=0;idx<count;idx++){
		var opts = _.clone(options);
		opts.path = opts.path+count;
		getHtml(opts,function(html){
			console.log('---------page: '+count+'	-------------------');
			console.log(html);
		});
	}
}

getJobs(2000);

//getHtml(options,function(html){
//	console.log(html);
//});
